package com.yy.crypto.controller;

import com.yy.crypto.common.entity.DResult;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.yy.crypto.annotation.DecryptionAnnotation;
import com.yy.crypto.annotation.EncryptionAnnotation;
import com.yy.crypto.common.entity.ResultBuilder;
import com.yy.crypto.entity.Teacher;

/**
 * @author yanglin
 * @description: 测试Controller
 * @email yling_dream@163.com
 * @date : Created in 2022/2/4 9:16
 */
@RestController
public class TestController implements ResultBuilder {

    /**
     * 直接返回对象，不加密
     * @param teacher Teacher对象
     * @return 不加密的对象
     */
    @PostMapping("/get")
    public DResult get(@Validated @RequestBody Teacher teacher) {
        return success(teacher);
    }

    /**
     * 直接返回对象，不加密
     * @param teacher Teacher对象
     * @return 不加密的对象
     */
    @PostMapping("/get1")
    public DResult get1(@Validated @RequestBody Teacher teacher) {
        return DResult.of(teacher);
    }

    /**
     * 返回加密后的数据
     * @param teacher Teacher对象
     * @return 返回加密后的数据 ResponseBody<Result>格式
     */
    @PostMapping("/encrypt")
    @EncryptionAnnotation
    public DResult encrypt(@Validated @RequestBody Teacher teacher) {
        /**
         * {
         *     "name": "马老师",
         *     "age": 56,
         *     "birthday": "2024-04-07 17:10:20"
         * }
         */
        return success(teacher);
    }

    /**
     * 返回加密后的数据
     * @param teacher Teacher对象
     * @return 返回加密后的数据 Result格式
     */
    @PostMapping("/encrypt1")
    @EncryptionAnnotation
    public DResult encrypt1(@Validated @RequestBody Teacher teacher) {
        return success(teacher);
    }

    /**
     * 返回解密后的数据
     * @param teacher Teacher对象
     * @return 返回解密后的数据
     */
    @PostMapping("/decrypt")
    @DecryptionAnnotation
    public DResult decrypt(@Validated @RequestBody Teacher teacher) {
        /**
         * {
         *  "text": "eecafe805e8fd8fa11357f9631d12b806085402637cce2adee747d190580a7d307c8c6f9b56915e9c4033a137588b4baff345f5cce5af976507048d90e92bf7a8759baa4a716a70326ab8cfbb106cadc66b0a808dc4f888d"
         * }
         */
        return success(teacher);
    }

}
